#封装接口，让test_shopping页面更整洁
from common.resquest_util import send
from common.file_util import *
def search_goods(name,goods_keyword,page=1,limit=8):
    data = {
        'path': '/api/products',
        'method': 'get',
        'params': {'keyword': goods_keyword, 'page': page, 'limit': limit},
    }
    return send(name,**data)

def add_group(name,group_name):
    data = {
        'path': '/adminapi/user/user_group/save.html',
        'method': 'post',
        'json': {'group_name': group_name},
        'headers': {
            'Authori-zation': f'Bearer {read_extract_variable("manage_token")}'}
    }
    return send(name,**data)

def add_coupon(name,testdate):
    data = {
        'path': '/adminapi/marketing/coupon/save_coupon',
        'method': 'post',
        'json': {"coupon_title": "testdata['name']", "coupon_price": testdate['price'], "type": 0, "use_min_price": 0,
                 "coupon_time": 1, "start_use_time": 0, "end_use_time": 0, "start_time": 0, "end_time": 0,
                 "receive_type": 1, "is_permanent": testdate['permanent'], "total_count": testdate['permanent_count'],
                 "sort": 0, "status": testdate['status'], "product_id": "", "category_id": 0},
        'headers': {
            'Authori-Zation': f'Bearer {read_extract_variable("manage_token")}'}

    }
    return send(name,**data)

def add_cart(name,testdate):
    data = {
        'path': '/api/cart/add',
        'method': 'post',
        'json':{"productId":"11","cartNum":1,"new":0,"uniqueId":"76eedee7","virtual_type":0},
        'headers': {
            'Authori-zation': f'Bearer {read_extract_variable("token")}'}
        }
    return send(name, **data)
def collect_goods(name,id):
    data = {
        'path': '/api/collect/add',
        'method': 'post',
        'json':{"id":id,"product":"product"},
        'headers': {
            'Authori-zation': f'Bearer {read_extract_variable("token")}'}
        }
    return send(name, **data)

def confirm(name,cartId):
    data = {
        'path': '/api/order/confirm',
        'method': 'post',
        'json':{"cartId":f"{cartId}","new":0,"addressId":0},
        'headers': {'Authori-zation': f'Bearer {read_extract_variable("token")}'}
    }
    return send(name,**data)
def create(name,orderKey):
    data = {
        'path':'/api/order/create/'f"{orderKey}",
        'method': 'post',
        'json':{"real_name":"egfsd","phone":"18340184593","addressId":1,"formId":"","couponId":0,"payType":"offline","useIntegral":False,"bargainId":0,"combinationId":0,"discountId":None,"pinkId":0,"advanceId":0,"seckill_id":0,"mark":"","from":"weixinh5","shipping_type":1,"new":0,"invoice_id":"","quitUrl":"http://47.110.161.180/pages/order_pay_status/index?&type=3&totalPrice=19"},
        'headers': {'Authori-zation': f'Bearer {read_extract_variable("token")}'}
    }
    return send(name,**data)
def order_list(name,orderId):
    data = {
        'path': f'/adminapi/order/list?page=1&limit=10&status=&pay_type=&data=&real_name={orderId}&type=',
        'method': 'get',
        'headers': {'Authori-Zation': f'Bearer {read_extract_variable("manage_token")}'}
    }
    return send(name,**data)
def pay_offline(name,id):
    data = {
        'path': '/adminapi/order/pay_offline/'f"{id}",
        'method': 'post',
        'headers': {'Authori-Zation': f'Bearer {read_extract_variable("manage_token")}'}

    }
    return send(name,**data)
def detail(name,orderId):
    data = {
        'path':'/api/order/detail/'f"{orderId}",
        'method': 'get',
        'headers': {'Authori-zation': f'Bearer {read_extract_variable("token")}'}
    }
    return send(name,**data)
def take(name,orderId):
    data = {
        'path': '/api/order/take',
        'method': 'post',
        'json':{"uni":f"{orderId}"},
        'headers': {'Authori-zation': f'Bearer {read_extract_variable("token")}'}
    }
    return send(name,**data)
def comment(name,unique):
    data = {
        'path': '/api/order/comment',
        'method': 'post',
        'json':{"comment":"hhh","product_score":5,"service_score":5,"pics":[],"unique":f"{unique}"},
        'headers': {'Authori-zation': f'Bearer {read_extract_variable("token")}'}
    }
    return send(name,**data)
def order_del(name,orderId):
    data = {
        'path': '/api/order/del',
        'method': 'post',
        'json':{"uni":f"{orderId}"},
        'headers': {'Authori-zation': f'Bearer {read_extract_variable("token")}'}
    }
    return send(name,**data)
def admin_del(name,id):
    data = {
        'path': '/adminapi/order/del/'f"{id}",
        'method': 'delete',
        'headers': {'Authori-Zation': f'Bearer {read_extract_variable("manage_token")}'}

    }
    return send(name,**data)